module(..., package.seeall)

--====================================================================--
-- POP UP: MYSTATS POPUP
--====================================================================--

--[[

******************
 - INFORMATION
******************

  - Sample scene.

--]]

--import the scrolling classes
local scrollView = require("scrollView")
local util       = require("util")

local imgPath = "images/"

local widget = require "widget"

new = function ()
	
	------------------
	-- Groups
	------------------
	
	local localGroup = display.newGroup()
	
	------------------
	-- Display Objects
	------------------
	
	local w, h = display.contentWidth, display.contentHeight
	local background = display.newImage( "background3.png" )
	background.xScale = 0.94
	background.yScale = 0.8
	background.alpha = 0.95
	
	--close button
	local btBatsut = function ( event )
		if event.phase == "release" then
			director:closePopUp()
		end
	end

	local btBatsu = ui.newButton{
					default = imgPath .. "cross_yellow_64.png",
					over = imgPath .. "cross_green_64.png",
					onEvent = btBatsut,
					id = "btBatsu"
	}
	btBatsu.x, btBatsu.y = 295,20

	--eo close button
	
	--popup header
	local headerBdr = display.newRect( 10, 0, display.contentWidth-20, 30 )
	headerBdr.strokeWidth = 1
	headerBdr:setFillColor(90, 90, 90)
	headerBdr:setStrokeColor(70, 70, 70)
	
	--popup title
	local popupTitle = display.newText( "Get Potion", 120, 5, native.systemFontBold, 20 )

	--buttons
	local function onButtonEvent( event )
		local btn = event.target
		if event.phase == "press" then
			print( "User has began pressing the button with id: " .. btn.id )
		elseif event.phase == "moved" then
			print( "User has dragged their finger while pressing the button." )
		elseif event.phase == "release" then
			print( "User has lifted finger from button." )        
		end
	end
	
	--btn get 1 token
	local button = widget.newButton{
		default = imgPath .. "btn_bg.png",
		over = imgPath .. "btn_black.png",
		label = "Get 1 Potion",
		font = "Helvetica-Bold",
		fontSize = 16,
		emboss = true,
		onEvent = onButtonEvent
	}
	button.x = display.contentCenterX
	button.y = 80
	button.xScale = 0.9
	button.yScale = 0.9

	--btn get 20 token
	local button20 = widget.newButton{
		default = imgPath .. "btn_bg.png",
		over = imgPath .. "btn_black.png",
		label = "Get 20 Potion",
		font = "Helvetica-Bold",
		fontSize = 16,
		emboss = true,
		onEvent = onButtonEvent
	}
	button20.x = display.contentCenterX
	button20.y = 130
	button20.xScale = 0.9
	button20.yScale = 0.9

	--btn get 100 token
	local button100 = widget.newButton{
		default = imgPath .. "btn_bg.png",
		over = imgPath .. "btn_black.png",
		label = "Get 100 Potion",
		font = "Helvetica-Bold",
		fontSize = 16,
		emboss = true,
		onEvent = onButtonEvent
	}
	button100.x = display.contentCenterX
	button100.y = 180
	button100.xScale = 0.9
	button100.yScale = 0.9

	
	--popup window group
	local headerGroup = display.newGroup();
	headerGroup.x = 0;
	headerGroup.y = 50;
	headerGroup:insert(headerBdr)
	headerGroup:insert(popupTitle)
	headerGroup:insert(btBatsu)
	headerGroup:insert(button)
	headerGroup:insert(button20)
	headerGroup:insert(button100)
	headerGroup.xScale = 1;
	headerGroup.yScale = 1;			
	--eo popup window group

	--tirana
	local potion = display.newImage( imgPath .. "potion_128.png" )
	potion.xScale = 2.0
	potion.yScale = 2.0
	potion.x = 250
	potion.y = 400
	---potion.rotation = -70
	potion.rotation = 0
	--tirana.xScale = -0.4


	------------------
	-- Listeners
	------------------
	
	local touched = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	
	local closed = function ( event )
		if event.phase == "ended" then
			director:closePopUp()
		end
	end
	

	
	--====================================================================--
	-- INITIALIZE
	--====================================================================--
	
	local function initVars ()
		
		------------------
		-- Inserts
		------------------
		
		localGroup:insert( background )
		localGroup:insert( potion )
		localGroup:insert( headerGroup )
		--localGroup:insert( scroller )
		--localGroup:insert( btBatsu )
		
		
		------------------
		-- Positions
		------------------
		
		--
		
		------------------
		-- Colors
		------------------
		
		--title:setTextColor( 255,255,255 )
		
		------------------
		-- Listeners
		------------------
		
		--background:addEventListener( "touch" , touched )
		
	end
	
	------------------
	-- Initiate variables
	------------------
	
	initVars()
	
	------------------
	-- MUST return a display.newGroup()
	------------------
	
	return localGroup
	
end
